#*-*coding:utf8*-*#
from django.db import models
from django.utils.timezone import *
import hashlib


class Department(models.Model):
    departmentname = models.CharField(max_length=20)


class User(models.Model):
    email    = models.EmailField(null=True)
    password = models.CharField(max_length=255)
    username = models.CharField(max_length=30)
    mobile   = models.CharField(null=True,max_length=11)
    is_active= models.IntegerField(default=1)
    gender = models.IntegerField(default=1)
    weibo = models.URLField(null=True)
    qq = models.CharField(max_length=20,null=True)
    birthday = models.DateField(default="1988-01-01")
    age = models.IntegerField(default=20)
    last_login = models.DateTimeField(auto_now=True)
    create = models.DateTimeField(auto_now=True)
    def is_authenticated(self):
        return True

    def hashed_password(self, password=None):
        if not password:
            return self.password
        else:
            return hashlib.md5(password.encode("utf8")).hexdigest()

    def check_password(self, password):
        if self.hashed_password(password) == self.password:
            return True
        return False